import { BwPageResultOutputSysApplicationAppGetListOutput } from '@bitwit/tenantapi'
import { api, useAxiosResponse } from '/@/api'
import { TableColumnConfigSelectOptionsModel } from './model'

export const requestMethods = {
  /** 获取应用列表 */
  onGetAppList(): Promise<TableColumnConfigSelectOptionsModel[]> {
    return new Promise((resolve, reject) => {
      api
        .apiSysApplicationGetListPost()
        .then((res) => {
          const resData =
            useAxiosResponse<BwPageResultOutputSysApplicationAppGetListOutput>(
              res
            )
          const appList =
            resData?.rows?.map((item) => ({
              label: item.name ?? '未命名应用',
              value: item.id ?? '',
            })) ?? []
          resolve(appList)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
}
